package adv.i31.robot;

import java.io.IOException;
import java.nio.charset.Charset;

import com.google.common.io.Files;

import android.app.Activity;
import android.content.res.AssetManager;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.widget.Button;

public class MainActivity extends Activity {

	@Override
	protected void onResume() {
		super.onResume();
		glsv.onResume();
		// sm.registerListener(mGyroscopeListener, gyroscope,
		// SensorManager.SENSOR_DELAY_NORMAL);
	}

	@Override
	protected void onPause() {
		super.onPause();
		glsv.onPause();
		// sm.unregisterListener(mGyroscopeListener);
	}

	private MyGLSurfaceView glsv;

	private SensorEventListener mGyroscopeListener = new SensorEventListener() {
		public void onSensorChanged(SensorEvent event) {
			System.out.format("X: %.3f  Y: %.3f  Z: %.3f\n", event.values[0], event.values[1],
					event.values[2]);

		}

		public void onAccuracyChanged(Sensor sensor, int accuracy) {
			// TODO Auto-generated method stub

		}
	};

	private Sensor gyroscope;

	private SensorManager sm;

	private Robot r;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		setContentView(R.layout.activity_main);
	

		//glsv = new MyGLSurfaceView(this);
		 glsv = (MyGLSurfaceView) findViewById(R.id.myGLSurfaceView1);

		r = new Robot();

		sm = (SensorManager) getApplicationContext().getSystemService(SENSOR_SERVICE);
		gyroscope = sm.getDefaultSensor(Sensor.TYPE_GYROSCOPE);

		Button buttonXMinus = (Button) findViewById(R.id.buttonXMinus);	
		buttonXMinus.setOnTouchListener(new OnTouchListener() {
			public boolean onTouch(View v, MotionEvent event) {
				switch (event.getAction()) {
					case MotionEvent.ACTION_DOWN:
						System.out.println("buttonXMinus ACTION_DOWN");
						return false;
					case MotionEvent.ACTION_UP:
						System.out.println("buttonXMinus ACTION_UP");
						return false;
				}
				// Listener did not consume the event
				return false;
			}
		});
		
		
		Button buttonXPlus = (Button) findViewById(R.id.buttonXPlus);	
		buttonXPlus.setOnTouchListener(new OnTouchListener() {
			public boolean onTouch(View v, MotionEvent event) {
				switch (event.getAction()) {
					case MotionEvent.ACTION_DOWN:
						System.out.println("buttonXPlus ACTION_DOWN");
						return false;
					case MotionEvent.ACTION_UP:
						System.out.println("buttonXPlus ACTION_UP");
						return false;
				}
				// Listener did not consume the event
				return false;
			}
		});
		
		Button buttonAus = (Button) findViewById(R.id.buttonAus);	
		buttonAus.setOnTouchListener(new OnTouchListener() {
			public boolean onTouch(View v, MotionEvent event) {
				switch (event.getAction()) {
					case MotionEvent.ACTION_DOWN:
						System.out.println("buttonAus ACTION_DOWN");
						return false;
					case MotionEvent.ACTION_UP:
						System.out.println("buttonAus ACTION_UP");
						return false;
				}
				// Listener did not consume the event
				return false;
			}
		});
		
		Button buttonYPlus = (Button) findViewById(R.id.ButtonYPlus);	
		buttonYPlus.setOnTouchListener(new OnTouchListener() {
			public boolean onTouch(View v, MotionEvent event) {
				switch (event.getAction()) {
					case MotionEvent.ACTION_DOWN:
						System.out.println("buttonYPlus ACTION_DOWN");
						return false;
					case MotionEvent.ACTION_UP:
						System.out.println("buttonYPlus ACTION_UP");
						return false;
				}
				// Listener did not consume the event
				return false;
			}
		});
		
		Button buttonYMinus = (Button) findViewById(R.id.buttonYMinus);	
		buttonYMinus.setOnTouchListener(new OnTouchListener() {
			public boolean onTouch(View v, MotionEvent event) {
				switch (event.getAction()) {
					case MotionEvent.ACTION_DOWN:
						System.out.println("buttonYMinus ACTION_DOWN");
						return false;
					case MotionEvent.ACTION_UP:
						System.out.println("buttonYMinus ACTION_UP");
						return false;
				}
				// Listener did not consume the event
				return false;
			}
		});
		
		Button buttonZMinus = (Button) findViewById(R.id.buttonZMinus);	
		buttonZMinus.setOnTouchListener(new OnTouchListener() {
			public boolean onTouch(View v, MotionEvent event) {
				switch (event.getAction()) {
					case MotionEvent.ACTION_DOWN:
						System.out.println("buttonZMinus ACTION_DOWN");
						return false;
					case MotionEvent.ACTION_UP:
						System.out.println("buttonZMinus ACTION_UP");
						return false;
				}
				// Listener did not consume the event
				return false;
			}
		});
		
		Button buttonZPlus = (Button) findViewById(R.id.buttonZPlus);	
		buttonZPlus.setOnTouchListener(new OnTouchListener() {
			public boolean onTouch(View v, MotionEvent event) {
				switch (event.getAction()) {
					case MotionEvent.ACTION_DOWN:
						System.out.println("buttonZPlus ACTION_DOWN");
						return false;
					case MotionEvent.ACTION_UP:
						System.out.println("buttonZPlus ACTION_UP");
						return false;
				}
				// Listener did not consume the event
				return false;
			}
		});
	}

}
